package logic

import (
	"context"
	"fmt"
	"merchantmanage/models/mysql"

	"merchantmanage/userrpc/internal/svc"
	"merchantmanage/userrpc/userrpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type GoodsAddLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewGoodsAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GoodsAddLogic {
	return &GoodsAddLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *GoodsAddLogic) GoodsAdd(in *userrpc.GoodsAddRequest) (*userrpc.GoodsAddResponse, error) {
	// todo: add your logic here and delete this line

	good := mysql.Goods{
		GoodName:  in.Goodname,
		GoodStace: in.Goodstace,
	}
	err := mysql.DB.Debug().Create(&good).Error
	if err != nil {
		return nil, fmt.Errorf("添加失败")
	}

	return &userrpc.GoodsAddResponse{
		GoodId: int64(good.ID),
	}, nil
}
